<?php
session_start();
    if($_SESSION['USER_TYPE']==2){
$menu=array(
	'main'=>array(
			'name'=>'管理首页',
			'action'=>'main',
			'type'=>array(1,2),
			'sub'=>array(
				array(
						'name'=>'快捷菜单',
						'type'=>array(1,2),
						'action'=>array(
						'?action=admin_personal&menu=user'=>'个人信息',
						'?menu=trade&action=admin_accounts_base&menu=trade'=>$lang['accounts_info'],
						'?action=admin_mail_list&type=inbox&menu=inquire'=>$lang['inbox'],
						'?action=admin_mail_list&type=outbox&menu=inquire'=>$lang['outbox'],
						'?action=m&m=friend&s=admin_friends&menu=inquire'=>'填加商友',
						'?action=m&m=friend&s=admin_friends_list&menu=inquire'=>'管理商友',
						),
					),
				),
		),
	'user'=>array(
			'name'=>'会员资料',
			'type'=>array(1,2),
			'sub'=>array(
					array(
						'name'=>'个人信息',
						'type'=>array(1,2),
						'action'=>array(
							'admin_personal'=>'个人资料',
							'setpassword'=>'设置密码',
						),
					),
				),	
		),
	'info'=>array(
			'name'=>'信息管理',
			'type'=>array(2),
		),
	'inquire'=>array(
			'name'=>'商机管理',
			'type'=>array(1,2),
			'sub'=>array(
					array(
						'name'=>'我的信箱',
						'type'=>array(1,2),
						'action'=>array(
						'admin_mail_list&type=inbox'=>'收件箱',
						'admin_mail_list&type=outbox'=>'发件箱',
						'admin_mail_list&type=savebox'=>'储存箱',
						'admin_mail_list&type=delbox'=>'垃圾箱',
						),
					),
					array(
						'name'=>'商机快递',
						'type'=>array(1,2),
						'action'=>array('admin_subscribe'=>'订阅管理','myfavorite'=>'我的收藏'),
					),
			),	
		),
        'train'=>array(
                            'name'=>'培训学习',
                            'type'=>array(1,2),
                    ),
	'trade'=>array(
		'name'=>'交易管理',
		'type'=>array(1,2),
		'sub'=>array(
				'1'=>array(
					'name'=>'资金管理',
					'type'=>array(1,2),
					'action'=>array(
					'admin_accounts_base'=>'账户信息',
					'admin_accounts_cashflow'=>'资金流水',
					'admin_accounts_pay'=>'账户充值',
					'admin_accounts_pickup'=>'资金提现',
					),
				)
			),	
	),
	'service'=>array(
			'name'=>'收费服务',
			'type'=>array(2),
			'sub'=>array(
				array(
					'name'=>'会员升级',
					'type'=>array(1,2),
					'action'=>array(
					'admin_upgrade_group'=>'在线升级',
					'admin_buy_point'=>'积分购买',
					'admin_adv_list'=>'广告服务',
					'admin_accounts_pay'=>'账户充值',
					),
				),
			),	
		),
	'usershop'=>array(
		'name'=>'旺铺设置',
		'type'=>array(2),
		'sub'=>array(
				array(
					'name'=>'网店设置',
					'type'=>array(2),
					'action'=>array(
						'template'=>'选择风格',
						'admin_shop_set'=>'模板设置',
						'add_domin'=>'绑定顶级域名'
					),
				),
				array(
					'name'=>'友情链接',
					'type'=>array(2),
					'action'=>array('admin_link'=>'新增链接','admin_link_list'=>'管理链接'),
				),
			),	
	),

);
    }else{
        $menu=array(
	'main'=>array(
			'name'=>'管理首页',
			'action'=>'main',
			'type'=>array(1,2),
			'sub'=>array(
				array(
						'name'=>'快捷菜单',
						'type'=>array(1,2),
						'action'=>array(
						'?action=admin_personal&menu=user'=>'个人信息',
						'?menu=trade&action=admin_accounts_base&menu=trade'=>$lang['accounts_info'],
						'?action=admin_mail_list&type=inbox&menu=inquire'=>$lang['inbox'],
						'?action=admin_mail_list&type=outbox&menu=inquire'=>$lang['outbox'],
						'?action=m&m=friend&s=admin_friends&menu=inquire'=>'填加商友',
						'?action=m&m=friend&s=admin_friends_list&menu=inquire'=>'管理商友',
						),
					),
				),
		),
	'user'=>array(
			'name'=>'会员资料',
			'type'=>array(1,2),
			'sub'=>array(
					array(
						'name'=>'个人信息',
						'type'=>array(1,2),
						'action'=>array(
							'admin_personal'=>'个人资料',
							'setpassword'=>'设置密码',
						),
					),
				),	
		),
	'inquire'=>array(
			'name'=>'商机管理',
			'type'=>array(1,2),
			'sub'=>array(
					array(
						'name'=>'我的信箱',
						'type'=>array(1,2),
						'action'=>array(
						'admin_mail_list&type=inbox'=>'收件箱',
						'admin_mail_list&type=outbox'=>'发件箱',
						'admin_mail_list&type=savebox'=>'储存箱',
						'admin_mail_list&type=delbox'=>'垃圾箱',
						),
					),
					array(
						'name'=>'商机快递',
						'type'=>array(1,2),
						'action'=>array('admin_subscribe'=>'订阅管理','myfavorite'=>'我的收藏'),
					),
			),	
		),
                    'train'=>array(
                            'name'=>'培训学习',
                            'type'=>array(1,2),
                    ),
	'trade'=>array(
		'name'=>'交易管理',
		'type'=>array(1,2),
		'sub'=>array(
				'1'=>array(
					'name'=>'资金管理',
					'type'=>array(1,2),
					'action'=>array(
					'admin_accounts_base'=>'账户信息',
					'admin_accounts_cashflow'=>'资金流水',
					'admin_accounts_pay'=>'账户充值',
					'admin_accounts_pickup'=>'资金提现',
					),
				)
			),	
	),
	'service'=>array(
			'name'=>'收费服务',
			'type'=>array(2),
			'sub'=>array(
				array(
					'name'=>'会员升级',
					'type'=>array(1,2),
					'action'=>array(
					'admin_upgrade_group'=>'在线升级',
					'admin_buy_point'=>'积分购买',
					'admin_adv_list'=>'广告服务',
					'admin_accounts_pay'=>'账户充值',
					),
				),
			),	
		),
	

);
    }
//----------------------
$dir=$config['webroot'].'/module/';
$handle = opendir($dir); 
while ($filename = readdir($handle))
{ 
	if($filename!="."&&$filename!="..")
	{
	  if(file_exists($dir.$filename.'/config.php'))
	  { 
		 include_once("$dir/$filename/config.php");
	  }
   }
}
foreach($menu as $key=>$v)
{
	if(isset($menu[$key]['sub']))
		ksort($menu[$key]['sub']);
	if(isset($admin))
	{//只有在admin情况下才调用。
		if(isset($right))
		{	//如果配置了会员模块，就删除超出权限的数组
			if(!in_array($v['name'],$right))
			{
				unset($menu[$key]);
			}
                        if(is_array($v['sub'])){
			foreach($v['sub'] as $skey=>$sv)
			{
				if(!in_array($sv['name'],$right))
				{
					unset($menu[$key]['sub'][$skey]);
				}
			}
                        }
		}
		else
		{
			if(!in_array($_SESSION['USER_TYPE'],$v['type']))
			{
				unset($menu[$key]);
			}
			foreach($v['sub'] as $skey=>$sv)
			{
				if(!in_array($_SESSION['USER_TYPE'],$sv['type']))
				{
					unset($menu[$key]['sub'][$skey]);
				}
			}
		}
		if($key!='main'&&is_array($menu[$key]['sub']))
		{
			$act=each($menu[$key]['sub']);$subkey=$act['key'];//取出第一个下标
			$act=@each($menu[$key]['sub'][$subkey]['action']);
			$menu[$key]['action']=$act['key'];
		}
	}
}
//----------------------
if(isset($tpl))
{
	$_GET['menu']=isset($_GET['menu'])?$_GET['menu']:'main';
	$tpl->assign("submenu",$menu[$_GET['menu']]);
	$tpl->assign("menu",$menu);
}
?>